package com.kinon.tyjaccount.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.kinon.tyjaccount.R;
import com.kinon.tyjaccount.sqlitebean.OrderBean;

import java.util.ArrayList;

/**打印适配器*/
public class UrgentDayingAdapter extends BaseAdapter{
	Context context;
	ArrayList<OrderBean> list;

	private OnAdapterClickListener listener = null;

	public static interface OnAdapterClickListener {
		void onItemClick(int position);
	}
	public void setAdapterClickListener(OnAdapterClickListener listener){
		this.listener = listener;
	}

	public UrgentDayingAdapter(Context context, ArrayList<OrderBean> list) {
		super();
		this.context = context;
		this.list = list;
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		final ViewHandle handle;
		if(view==null){
			handle=new ViewHandle();
			view=LayoutInflater.from(context).inflate(R.layout.item_daying, null);
			handle.tv_bianhao=(TextView)view.findViewById(R.id.tv_order);
			handle.tv_name=(TextView)view.findViewById(R.id.tv_name);
			handle.tv_jine=(TextView)view.findViewById(R.id.tv_jine);
			handle.tv_shijian=(TextView)view.findViewById(R.id.tv_time);
			handle.btn_tuikuan=(Button)view.findViewById(R.id.btn_tuikuan);
			handle.btn_tongzhi=(Button)view.findViewById(R.id.btn_tongzhi);
			view.setTag(handle);
		}else {
			handle = (ViewHandle) view.getTag();
		}

		handle.tv_bianhao.setText(list.get(position).getDayno());
		handle.tv_name.setText(list.get(position).getName());
		handle.tv_jine.setText("￥"+list.get(position).getTotal());
		handle.tv_shijian.setText(list.get(position).getOrder_time());

		if (list.get(position).getPrint()==1) {
			handle.btn_tuikuan.setText("已打印");
		}else {
			handle.btn_tuikuan.setText("打印");
		}
		if (list.get(position).getNotice()==1) {
			handle.btn_tongzhi.setText("已通知");
			handle.btn_tongzhi.setEnabled(false);
		}else {
			handle.btn_tongzhi.setEnabled(true);
			handle.btn_tongzhi.setText("通知");
		}
		handle.btn_tuikuan.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if(listener!=null) {
					listener.onItemClick(position);
				}
			}
		});

		return view;
	}
	class ViewHandle {
		/**订单编号*/
		TextView tv_bianhao;
		/**姓名*/
		TextView tv_name;
		/**价格*/
		TextView tv_jine;
		/**时间*/
		TextView tv_shijian;
		/**打印*/
		Button btn_tuikuan;
		/**通知*/
		Button btn_tongzhi;
	}
}
